package example.array.p16;

import java.util.HashSet;
import java.util.Set;

/**
 * @author 17976
 */
public class Main {
    public static void main(String[] args)  throws Exception {
        String[] arr1 = {"1", "2", "3"};
        String[] arr2 = {"4", "5", "6"};
        String[] resultUnion = union(arr1, arr2);
        System.out.println("并集的结果如下：");
        for (String str : resultUnion) {
            System.out.println(str);
        }
    }public static String[] union(String[] arr1, String[] arr2) {
            Set<String> set = new HashSet<String>();
            for (String str : arr1) {
                set.add(str);
            }
            for (String str : arr2) {
                set.add(str);
            }
            String[] result = {  };
            return set.toArray(result);
    }
}
